﻿using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class SearchAquacultureTechControl : YuanlinUserControl
    {
        protected ValuedTextBox searchTextBox;
        protected IButton SearchButton;
        private int aquacultureGuiGeId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.AquacultureGuiGeId);
        private string character = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.Character);
        private int categoryType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryType);

        protected override void OnLoad(EventArgs e)
        {
            SearchButton.Click += new EventHandler(SearchButton_Click);
        }
        private void SearchButton_Click(object sender, System.EventArgs e)
        {
            string path = "";
            if (categoryType == (int)CategoryType.Fishery)
            {
                path = SiteUrls.Instance().GetTechAquacultureListUrl(0, categoryType);
            }
            if (aquacultureGuiGeId > 0)
            {
                path = SiteUrls.Instance().GetTechAquacultureListUrl(aquacultureGuiGeId, categoryType);
            }
            else if (!string.IsNullOrEmpty(character))
            {
                path = SiteUrls.Instance().GetTechAquacultureListUrl(character, categoryType);
            }

            if (!string.IsNullOrEmpty(this.searchTextBox.Value))
            {
                if (path.IndexOf("?") > 0)
                {
                    path += string.Format("&QueryText={0}", System.Web.HttpUtility.UrlEncode(this.searchTextBox.Value));
                }
                else
                {
                    path += string.Format("?QueryText={0}", System.Web.HttpUtility.UrlEncode(this.searchTextBox.Value));
                }
            }
            else
            {
                return;
            }

            Page.Response.Redirect(path);

        }
    }
}
